package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataAccess {
	private String host;
	private String username;
	private String password;
	private String dbName;
	private int port;

	public DataAccess(String host, String username, String password,
			String dbName, int port) {
		this.host = host;
		this.username = username;
		this.password = password;
		this.dbName = dbName;
		this.port = port;
	}
	
	public DataAccess(){
		this.host = "localhost";
		this.port = 3306;
		this.username = "root";
		this.password = "angellove&&641";
		this.dbName = "tokenauthen";
	}

	public Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://" + this.host + ":" + this.port + "/"
					+ dbName;
			return DriverManager.getConnection(url, username, password);
		} catch (Exception e) {
			System.exit(0);
			return null;
		}
	}

	public void disConnect(Connection con) {
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDbName() {
		return dbName;
	}

	public void setDbName(String dbName) {
		this.dbName = dbName;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}
	
}